#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <iterator>
#include <algorithm>    //sort() 
using namespace std;

/*
    Name: 简单的类设计和文件操作 
	Copyright: 
	Author: Quietism
	Date: 08/05/16 20:45
	Description: c++ 简单的类设计和文件操作 
*/

class Student{
	protected:	//private 无法被继承 
		int No;
		string name;
	public:
		Student(){}
		//No name
		Student(int No, string name){
			this->No = No;
			this->name = name;
		}
		int getNo(){
			return this->No;
		}
		string getName(){
			return this->name;
		}
		void setNo(int arg){
			this->No = arg;
		}
		void setName(string arg){
			this->name = arg;
		}
};

class Undergraduate:private Student{	//使用 private 方式继承,使基类的数据成员在子类中访问限定为 private 
	private:
		int score_1, score_2, score_3;

	public: 
		Undergraduate(){}
		Undergraduate(int No, string name, int score1, int score2, int score3){
			this->No = No;
			this->name = name;
			this->score_1 = score1;
			this->score_2 = score2;
			this->score_3 = score3;
		}
		void setScore1(int arg){
			this->score_1 = arg;
		}
		void setScore2(int arg){
			this->score_2 = arg;
		}
		void setScore3(int arg){
			this->score_3 = arg;
		}
		
		int getScore1(){
			return this->score_1;
		}
		int getScore2(){
			return this->score_2;
		}
		int getScore3(){
			return this->score_3;
		} 
	 
		//@override 因为是用 private 方式继承的，所以子类对象无法访问基类成员，需要覆盖(重写) 
		int getNo(){
			return this->No;
		}
		string getName(){
			return this->name;
		}
		void setNo(int arg){
			this->No = arg;
		}
		void setName(string arg){
			this->name = arg;
		}
		void  display(){
			cout<<this->No<<'\t'<<this->name<<'\t'<<this->score_1<<'\t'<<this->score_2<<'\t'<<this->score_3<<endl;
		}
};

bool compare(Undergraduate &u1, Undergraduate &u2) {	// 按三门课程总成绩降序排列 
	return (u1.getScore1()+u1.getScore2()+u1.getScore3()) > (u2.getScore1()+u2.getScore2()+u2.getScore3());  
}  

#define DATA_FILE "data.txt"
/*
101  John   89  67  63
103  Tom   87  89  67
205  Peter 45  85  58
203  Jack  87  56  98
406  Hack  89  75  48
592  Ham  89   46  97
*/
int main(/*int argc, char *argv[]*/){
	string name;
	int No,s1,s2,s3;
	ifstream data;
	vector<Undergraduate> vec;
	data.open(DATA_FILE); 
	if (! data.is_open()){ 
		cout << "Error opening file"; 
		return 1; 
	}
	while(!data.eof()){
		data>>No>>name>>s1>>s2>>s3;
		vec.push_back(Undergraduate(No,name,s1,s2,s3));
	}
	
	sort(vec.begin(),vec.end(), compare); 
	
	for(vector<Undergraduate>::iterator i =vec.begin(); i != vec.end(); i++){
		(*i).display();
	}
	return 0;
}